Load all required libraries.
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.3 v dplyr 1.0.7
## v tidyr 1.1.3 v stringr 1.4.0
## v readr 2.0.0 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(broom)
Read in raw data from RDS.
raw_data <- readRDS("./year2.RDS")
Make a few small modifications to names and data for visualizations.
final_data <- raw_data %>% mutate(log_copy_per_L = log10(mean_copy_num_L)) %>%
rename(Facility = wrf) %>%
mutate(Facility = recode(Facility,
"NO" = "WRF A",
"MI" = "WRF B",
"CC" = "WRF C"))
Seperate the data by gene target to ease layering in the final plot
#make three data layers
only_positives <<- subset(final_data, (!is.na(final_data$Facility)))
only_n1 <- subset(only_positives, target == "N1")
only_n2 <- subset(only_positives, target == "N2")
only_background <<-final_data %>%
select(c(date, cases_cum_clarke, new_cases_clarke, X7_day_ave_clarke)) %>%
group_by(date) %>% summarise_if(is.numeric, mean)
#specify fun colors
background_color <- "#7570B3"
seven_day_ave_color <- "#E6AB02"
marker_colors <- c("N1" = '#1B9E77',"N2" ='#D95F02')
#remove facilty C for now
#only_n1 <- only_n1[!(only_n1$Facility == "WRF C"),]
#only_n2 <- only_n2[!(only_n2$Facility == "WRF C"),]
only_n1 <- only_n1[!(only_n1$Facility == "WRF A" & only_n1$date == "2020-11-02"), ]
only_n2 <- only_n2[!(only_n2$Facility == "WRF A" & only_n2$date == "2020-11-02"), ]
Build the main plot
#first layer is the background epidemic curve
p1 <- only_background %>%
plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~new_cases_clarke,
type = "bar",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Daily Cases: ', new_cases_clarke),
alpha = 0.5,
name = "Daily Reported Cases",
color = background_color,
colors = background_color,
showlegend = FALSE) %>%
layout(yaxis = list(title = "Clarke County Daily Cases", showline=TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#renders the main plot layer two as seven day moving average
p1 <- p1 %>% plotly::add_trace(x = ~date, y = ~X7_day_ave_clarke,
type = "scatter",
mode = "lines",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Seven-Day Moving Average: ', X7_day_ave_clarke),
name = "Seven Day Moving Average Athens",
line = list(color = seven_day_ave_color),
showlegend = FALSE)
#renders the main plot layer three as positive target hits
p2 <- plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n1,
symbol = ~Facility,
marker = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n2,
symbol = ~Facility,
marker = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(yaxis = list(title = "SARS CoV-2 Copies/L",
showline = TRUE,
type = "log",
dtick = 1,
automargin = TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#adds the limit of detection dashed line
p2 <- p2 %>% plotly::add_segments(x = as.Date("2021-06-30"),
xend = ~max(date + 10),
y = 3571.429, yend = 3571.429,
opacity = 0.35,
line = list(color = "black", dash = "dash")) %>%
layout(annotations = list(x = as.Date("2021-06-30"), y = 3.8, xref = "x", yref = "y",
text = "Limit of Detection", showarrow = FALSE))
p1
p2
Combine the two main plot pieces as a subplot
#seperate n1 and n2 frames by site
#n1
wrf_a_only_n1 <- subset(only_n1, Facility == "WRF A")
wrf_b_only_n1 <- subset(only_n1, Facility == "WRF B")
wrf_c_only_n1 <- subset(only_n1, Facility == "WRF C")
#n2
wrf_a_only_n2 <- subset(only_n2, Facility == "WRF A")
wrf_b_only_n2 <- subset(only_n2, Facility == "WRF B")
wrf_c_only_n2 <- subset(only_n2, Facility == "WRF C")
#rejoin the old data frames then seperate in to averages for each plant.
wrfa_both <- full_join(wrf_a_only_n1, wrf_a_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke", "X7_day_ave_clarke", "Facility", "collection_num", "target", "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "mean_total_copies", "sd_total_copies", "log_copy_per_L")
wrfb_both <- full_join(wrf_b_only_n1, wrf_b_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke", "X7_day_ave_clarke", "Facility", "collection_num", "target", "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "mean_total_copies", "sd_total_copies", "log_copy_per_L")
wrfc_both <- full_join(wrf_c_only_n1, wrf_c_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke", "X7_day_ave_clarke", "Facility", "collection_num", "target", "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "mean_total_copies", "sd_total_copies", "log_copy_per_L")
#get max date
maxdate <- max(wrfa_both$date)
mindate <- min(wrfa_both$date)
Build loess smoothing figures figures
This makes the individual plots
#**************************************WRF A PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_botha <- ggplot(wrfa_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_botha<<-..y..), method = "loess", color = '#1B9E77',
span = 0.3, n = 267)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_botha
## `geom_smooth()` using formula 'y ~ x'
fit_botha
## [1] 11.53128 11.56979 11.60796 11.64580 11.68331 11.72049 11.75734 11.79389
## [9] 11.83012 11.86605 11.90168 11.93701 11.97205 12.00680 12.04122 12.07533
## [17] 12.10912 12.14260 12.17575 12.20858 12.24122 12.27375 12.30610 12.33821
## [25] 12.37003 12.40148 12.43250 12.46304 12.49302 12.52286 12.55287 12.58281
## [33] 12.61246 12.64160 12.67000 12.69744 12.72505 12.75386 12.78348 12.81351
## [41] 12.84355 12.87323 12.90214 12.92989 12.95610 12.98036 13.00229 13.02150
## [49] 13.04051 13.06127 13.08254 13.10303 13.12151 13.13669 13.14733 13.15429
## [57] 13.15928 13.16233 13.16348 13.16274 13.16016 13.15575 13.14955 13.14160
## [65] 13.13190 13.12051 13.10743 13.09271 13.07638 13.05845 13.03551 13.00545
## [73] 12.97026 12.93194 12.89251 12.85395 12.81827 12.78747 12.75571 12.71755
## [81] 12.67563 12.63259 12.59104 12.55364 12.52300 12.49655 12.47006 12.44370
## [89] 12.41764 12.39203 12.36704 12.34285 12.31960 12.29747 12.27661 12.25721
## [97] 12.23941 12.22339 12.20930 12.19765 12.18858 12.18175 12.17679 12.17338
## [105] 12.17114 12.16974 12.16882 12.16803 12.16702 12.16545 12.16295 12.16008
## [113] 12.15766 12.15573 12.15438 12.15365 12.15362 12.15436 12.15601 12.15861
## [121] 12.16207 12.16625 12.17106 12.17638 12.18210 12.18811 12.19430 12.20055
## [129] 12.20675 12.21280 12.21858 12.22398 12.23050 12.23923 12.24948 12.26054
## [137] 12.27171 12.28228 12.29155 12.29882 12.30337 12.30462 12.30287 12.29879
## [145] 12.29304 12.28627 12.27915 12.27234 12.26650 12.26229 12.26036 12.26139
## [153] 12.26603 12.27238 12.27825 12.28388 12.28950 12.29534 12.30164 12.30862
## [161] 12.31652 12.32557 12.33600 12.34805 12.36195 12.37793 12.39623 12.42023
## [169] 12.45231 12.49111 12.53528 12.58349 12.63438 12.68661 12.73883 12.78970
## [177] 12.83787 12.88200 12.92074 12.95274 12.97667 13.00047 13.03133 13.06675
## [185] 13.10420 13.14117 13.17516 13.20366 13.22414 13.23410 13.23498 13.23022
## [193] 13.22036 13.20592 13.18742 13.16538 13.14033 13.11279 13.08327 13.05231
## [201] 13.02043 12.98815 12.95599 12.92448 12.88981 12.84860 12.80201 12.75119
## [209] 12.69729 12.64146 12.58486 12.52864 12.47395 12.42194 12.37377 12.33059
## [217] 12.28921 12.24620 12.20237 12.15851 12.11542 12.07392 12.03480 11.99688
## [225] 11.95860 11.92018 11.88184 11.84382 11.80633 11.76960 11.73385 11.69930
## [233] 11.66619 11.63473 11.60515 11.57767 11.55251 11.52927 11.50733 11.48668
## [241] 11.46726 11.44906 11.43203 11.41614 11.40134 11.38765 11.37510 11.36370
## [249] 11.35345 11.34438 11.33650 11.32981 11.32433 11.32006 11.31698 11.31510
## [257] 11.31443 11.31496 11.31669 11.31965 11.32382 11.32921 11.33583 11.34367
## [265] 11.35275 11.36307 11.37463
#assign fits to a vector
both_trenda <- fit_botha
#extract y min and max for each
limits_botha <- ggplot_build(extract_botha)$data
## `geom_smooth()` using formula 'y ~ x'
limits_botha <- as.data.frame(limits_botha)
both_ymina <- limits_botha$ymin
both_ymaxa <- limits_botha$ymax
#reassign dataframes (just to be safe)
work_botha <- wrfa_both
#fill in missing dates to smooth fits
work_botha <- work_botha %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_botha <- work_botha$date
#create a new smooth dataframe to layer
smooth_frame_botha <- data.frame(date_vec_botha, both_trenda, both_ymina, both_ymaxa)
#WRF A
#plot smooth frames
p_wrf_a <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_botha, y = ~both_trenda,
data = smooth_frame_botha,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha,
'</br> Median Log Copies: ', round(both_trenda, digits = 2)),
line = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_botha, ymin = ~both_ymina, ymax = ~both_ymaxa,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxa, digits = 2),
'</br> Min Log Copies: ', round(both_ymina, digits = 2)),
name = "",
fillcolor = '#1B9E77',
line = list(color = '#1B9E77')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF A") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfa_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#1B9E77', size = 6, opacity = 0.65))
p_wrf_a
save(p_wrf_a, file = "./site_objects/wrf_a_year2.rda")
#**************************************WRF B PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothb <- ggplot(wrfb_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothb<<-..y..), method = "loess", color = '#D95F02',
span = 0.3, n = 267)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothb
## `geom_smooth()` using formula 'y ~ x'
fit_bothb
## [1] 10.71296 10.80588 10.89691 10.98605 11.07327 11.15856 11.24192 11.32332
## [9] 11.40275 11.48020 11.55565 11.62910 11.70052 11.76990 11.83726 11.90263
## [17] 11.96605 12.02756 12.08721 12.14503 12.20075 12.25413 12.30531 12.35442
## [25] 12.40159 12.44693 12.49060 12.53270 12.57337 12.61198 12.64802 12.68181
## [33] 12.71366 12.74387 12.77276 12.80064 12.82652 12.84938 12.86950 12.88718
## [41] 12.90268 12.91630 12.92831 12.93900 12.94865 12.95754 12.96595 12.97417
## [49] 12.98033 12.98305 12.98331 12.98209 12.98038 12.97916 12.97942 12.98032
## [57] 12.98037 12.97966 12.97823 12.97615 12.97349 12.97032 12.96668 12.96265
## [65] 12.95829 12.95367 12.94884 12.94387 12.93882 12.93376 12.92910 12.92494
## [73] 12.92089 12.91654 12.91150 12.90536 12.89771 12.88817 12.87789 12.86805
## [81] 12.85819 12.84791 12.83678 12.82436 12.81024 12.79476 12.77857 12.76169
## [89] 12.74415 12.72599 12.70721 12.68786 12.66795 12.64751 12.62656 12.60514
## [97] 12.58326 12.56096 12.53826 12.51386 12.48674 12.45733 12.42608 12.39342
## [105] 12.35979 12.32562 12.29134 12.25741 12.22425 12.19229 12.16198 12.12598
## [113] 12.07981 12.02822 11.97594 11.92774 11.88835 11.86251 11.84569 11.83026
## [121] 11.81633 11.80403 11.79346 11.78475 11.77801 11.77336 11.77092 11.77079
## [129] 11.77310 11.77797 11.78550 11.79582 11.81224 11.83666 11.86706 11.90143
## [137] 11.93777 11.97407 12.00832 12.03851 12.06263 12.08598 12.11452 12.14732
## [145] 12.18339 12.22179 12.26154 12.30168 12.34126 12.37931 12.41486 12.44696
## [153] 12.47463 12.49887 12.52144 12.54255 12.56243 12.58130 12.59939 12.61690
## [161] 12.63408 12.65112 12.66827 12.68573 12.70373 12.72250 12.74224 12.76420
## [169] 12.78909 12.81639 12.84557 12.87610 12.90743 12.93905 12.97042 13.00101
## [177] 13.03028 13.05771 13.08277 13.10491 13.12362 13.14279 13.16573 13.19101
## [185] 13.21719 13.24286 13.26658 13.28693 13.30247 13.31178 13.31641 13.31889
## [193] 13.31928 13.31762 13.31398 13.30841 13.30095 13.29167 13.28061 13.26783
## [201] 13.25338 13.23731 13.21969 13.20055 13.17976 13.15716 13.13282 13.10681
## [209] 13.07919 13.05002 13.01936 12.98729 12.95386 12.91913 12.88318 12.84606
## [217] 12.80440 12.75624 12.70375 12.64914 12.59459 12.54227 12.49440 12.44820
## [225] 12.39978 12.34964 12.29826 12.24613 12.19374 12.14158 12.09014 12.03990
## [233] 11.99136 11.94500 11.90130 11.86077 11.82388 11.78992 11.75763 11.72669
## [241] 11.69678 11.66759 11.63880 11.61009 11.58115 11.55232 11.52418 11.49675
## [249] 11.47008 11.44417 11.41906 11.39479 11.37137 11.34876 11.32689 11.30575
## [257] 11.28532 11.26561 11.24659 11.22827 11.21063 11.19366 11.17735 11.16170
## [265] 11.14670 11.13233 11.11859
#assign fits to a vector
both_trendb <- fit_bothb
#extract y min and max for each
limits_bothb <- ggplot_build(extract_bothb)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothb <- as.data.frame(limits_bothb)
both_yminb <- limits_bothb$ymin
both_ymaxb <- limits_bothb$ymax
#reassign dataframes (just to be safe)
work_bothb <- wrfb_both
#fill in missing dates to smooth fits
work_bothb <- work_bothb %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothb <- work_bothb$date
#create a new smooth dataframe to layer
smooth_frame_bothb <- data.frame(date_vec_bothb, both_trendb, both_yminb, both_ymaxb)
#WRF B
#plot smooth frames
p_wrf_b <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothb, y = ~both_trendb,
data = smooth_frame_bothb,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb,
'</br> Median Log Copies: ', round(both_trendb, digits = 2)),
line = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothb, ymin = ~both_yminb, ymax = ~both_ymaxb,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxb, digits = 2),
'</br> Min Log Copies: ', round(both_yminb, digits = 2)),
name = "",
fillcolor = '#D95F02',
line = list(color = '#D95F02')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF B") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfb_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#D95F02', size = 6, opacity = 0.65))
p_wrf_b
save(p_wrf_b, file = "./site_objects/wrf_b_year2.rda")
#**************************************WRF C PLOT********************************************** #add trendlines #extract data from geom_smooth # *********************************span 0.6*********************************** #*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothc <- ggplot(wrfc_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothc<<-..y..), method = "loess", color = '#E7298A',
span = 0.3, n = 267)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothc
## `geom_smooth()` using formula 'y ~ x'
fit_bothc
## [1] 10.82121 10.88659 10.95074 11.01364 11.07526 11.13557 11.19454 11.25213
## [9] 11.30833 11.36310 11.41641 11.46823 11.51853 11.56734 11.61475 11.66080
## [17] 11.70554 11.74903 11.79132 11.83246 11.87197 11.90949 11.94524 11.97943
## [25] 12.01230 12.04406 12.07493 12.10514 12.13491 12.16210 12.18526 12.20560
## [33] 12.22432 12.24263 12.26176 12.28290 12.30549 12.32805 12.35048 12.37267
## [41] 12.39452 12.41591 12.43675 12.45692 12.47631 12.49482 12.51234 12.52877
## [49] 12.54626 12.56616 12.58710 12.60769 12.62656 12.64235 12.65368 12.66134
## [57] 12.66713 12.67116 12.67355 12.67442 12.67388 12.67207 12.66908 12.66505
## [65] 12.66009 12.65432 12.64786 12.64083 12.63334 12.62551 12.61599 12.60373
## [73] 12.58932 12.57338 12.55648 12.53924 12.52223 12.50607 12.48909 12.46972
## [81] 12.44870 12.42672 12.40453 12.38282 12.36233 12.34144 12.31837 12.29357
## [89] 12.26751 12.24062 12.21337 12.18622 12.15961 12.13399 12.10983 12.08758
## [97] 12.06769 12.05062 12.03681 12.02580 12.01664 12.00906 12.00281 11.99761
## [105] 11.99320 11.98933 11.98573 11.98215 11.97830 11.97394 11.96881 11.96526
## [113] 11.96501 11.96676 11.96925 11.97120 11.97133 11.96837 11.96382 11.95998
## [121] 11.95677 11.95408 11.95184 11.94995 11.94831 11.94685 11.94546 11.94406
## [129] 11.94255 11.94085 11.93886 11.93649 11.93259 11.92644 11.91859 11.90962
## [137] 11.90010 11.89060 11.88167 11.87390 11.86784 11.86092 11.85076 11.83821
## [145] 11.82412 11.80932 11.79468 11.78104 11.76925 11.76016 11.75462 11.75347
## [153] 11.75757 11.76553 11.77533 11.78687 11.80003 11.81472 11.83081 11.84822
## [161] 11.86682 11.88650 11.90718 11.92872 11.95103 11.97401 11.99753 12.02465
## [169] 12.05786 12.09618 12.13867 12.18436 12.23230 12.28152 12.33106 12.37998
## [177] 12.42730 12.47208 12.51334 12.55014 12.58151 12.61533 12.65815 12.70705
## [185] 12.75909 12.81136 12.86091 12.90483 12.94018 12.96404 12.97935 12.99113
## [193] 12.99957 13.00489 13.00726 13.00689 13.00398 12.99872 12.99130 12.98193
## [201] 12.97080 12.95810 12.94403 12.92879 12.91071 12.88834 12.86221 12.83288
## [209] 12.80086 12.76671 12.73096 12.69414 12.65680 12.61948 12.58271 12.54702
## [217] 12.50697 12.45874 12.40538 12.34993 12.29544 12.24492 12.20144 12.16070
## [225] 12.11690 12.07079 12.02313 11.97468 11.92619 11.87841 11.83212 11.78805
## [233] 11.74697 11.70964 11.67680 11.64922 11.62765 11.60935 11.59157 11.57500
## [241] 11.56035 11.54832 11.53963 11.53497 11.53504 11.53873 11.54455 11.55273
## [249] 11.56347 11.57698 11.59349 11.61319 11.63630 11.66263 11.69184 11.72394
## [257] 11.75891 11.79675 11.83747 11.88105 11.92751 11.97682 12.02900 12.08403
## [265] 12.14192 12.20267 12.26626
#assign fits to a vector
both_trendc <- fit_bothc
#extract y min and max for each
limits_bothc <- ggplot_build(extract_bothc)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothc <- as.data.frame(limits_bothc)
both_yminc <- limits_bothc$ymin
both_ymaxc <- limits_bothc$ymax
#reassign dataframes (just to be safe)
work_bothc <- wrfc_both
#fill in missing dates to smooth fits
work_bothc <- work_bothc %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothc <- work_bothc$date
#create a new smooth dataframe to layer
smooth_frame_bothc <- data.frame(date_vec_bothc, both_trendc, both_yminc, both_ymaxc)
#WRF C
#plot smooth frames
p_wrf_c <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothc, y = ~both_trendc,
data = smooth_frame_bothc,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc,
'</br> Median Log Copies: ', round(both_trendc, digits = 2)),
line = list(color = '#E7298A', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothc, ymin = ~both_yminc, ymax = ~both_ymaxc,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxc, digits = 2),
'</br> Min Log Copies: ', round(both_yminc, digits = 2)),
name = "",
fillcolor = '#E7298A',
line = list(color = '#E7298A')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF C") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfc_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#E7298A', size = 6, opacity = 0.65))
p_wrf_c
save(p_wrf_c, file = "./site_objects/wrf_c_year2.rda")
keeping in case
#save(wrfa_both, file = "./plotly_objs/wrfa_both.rda")
#save(wrfb_both, file = "./plotly_objs/wrfb_both.rda")
#save(wrfc_both, file = "./plotly_objs/wrfc_both.rda")
#save(date_vec_botha, file = "./plotly_objs/date_vec_botha.rda")
#save(date_vec_bothb, file = "./plotly_objs/date_vec_bothb.rda")
#save(date_vec_bothc, file = "./plotly_objs/date_vec_bothc.rda")
#save(both_ymina, file = "./plotly_objs/both_ymina.rda")
#save(both_ymaxa, file = "./plotly_objs/both_ymaxa.rda")
#save(both_yminb, file = "./plotly_objs/both_yminb.rda")
#save(both_ymaxb, file = "./plotly_objs/both_ymaxb.rda")
#save(both_yminc, file = "./plotly_objs/both_yminc.rda")
#save(both_ymaxc, file = "./plotly_objs/both_ymaxc.rda")